package com.aigou.admin.dao.impl;

import com.aigou.admin.utils.JDBCUtils;
import com.aigou.admin.dao.CarouselFigureDao;
import com.aigou.admin.entity.CarouselFigure;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author: Hor
 * @Date: 2024/11/29 09:19
 * @Version: 1.0
 */
@Repository
public class CarouselFigureDaoImpl implements CarouselFigureDao {
    /**
     * 查询所有的用户
     *
     * @return 用户列表
     */
    @Override
    public List<CarouselFigure> selectAll() {
        return JDBCUtils.executeQuery(CarouselFigure.class, "select * from s_carousel_figure");
    }

    @Override
    public CarouselFigure selectById(String id) {
        List<CarouselFigure> users = JDBCUtils.executeQuery(CarouselFigure.class, "select * from s_carousel_figure where id = ? ",  id);
        if (users.isEmpty()) {
            return null;
        }
        return users.get(0);
    }

    @Override
    public Boolean insert(CarouselFigure carouselFigure) {
        int rows = JDBCUtils.executeUpdate("insert into s_carousel_figure(id,url,sequence_num) values(?,?,?)",carouselFigure.getId(),carouselFigure.getUrl(),carouselFigure.getSequence_num());
        return rows > 0;
    }

    @Override
    public Boolean update(CarouselFigure carouselFigure) {
        int rows = JDBCUtils.executeUpdate("update s_carousel_figure set id =?,url=?,sequence_num=? where id = ?", carouselFigure.getId(), carouselFigure.getUrl(),carouselFigure.getSequence_num(),carouselFigure.getId());
        return rows > 0;
    }

    @Override
    public Boolean delete(String id) {
        int rows = JDBCUtils.executeUpdate("delete from s_carousel_figure where id = ?", id);
        return rows >0;
    }

    @Override
    public Integer selectCount() {
        return JDBCUtils.executeCount("select count(*) from s_carousel_figure");
    }

    @Override
    public List<CarouselFigure> selectUserByLimit(Integer start, Integer limit) {
        return JDBCUtils.executeQuery(CarouselFigure.class, "select * from s_carousel_figure limit ?,?", start, limit);
    }
}
